#!/bin/bash

# Determine directory for scripts
DIR=`dirname $0`

# Make sure that $DATE and $UNIXTIME are the same in this script and config
DATE=`date +%Y-%m-%d_%H%M%S`
UNIXTIME=`date +%s`

# Load the config
source "$DIR/lweamonit_config.sh"

# Load an image from webcam, if possible
source "$DIR/get_image.sh"

QUERY="INSERT INTO images(time, filename) VALUES(FROM_UNIXTIME(${UNIXTIME}), '${FILENAME}')"

mysql --host="$DB_HOSTNAME" --port=$DB_PORT -u"$DB_USERNAME" -p"$DB_PASSWORD" "$DB_NAME" -e "$QUERY"
